package com.katze.boot.applet.ssh.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.katze.ssh.SecureShellSession;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serial;
import java.io.Serializable;
import java.util.Date;

@TableName("ssh_session")
public class SshSessionEntity implements SecureShellSession, Serializable {
    @Serial
    private static final long serialVersionUID = 1L;

    @TableId(type = IdType.ASSIGN_UUID)
    private String id;

    /**
     * 所有者
     */
    private String owner;

    /**
     * 服务端ip
     */
    private String host;

    /**
     * 服务端端口
     */
    private int port;

    /**
     * 用户名
     */
    private String username;

    /**
     * 密码
     */
    private String password;

    @TableField(fill = FieldFill.INSERT)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getOwner() {
        return owner;
    }

    public void setOwner(String owner) {
        this.owner = owner;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    @Override
    public boolean equals(Object obj) {
        SshSessionEntity entity = (SshSessionEntity) obj;
        return this.host != null && this.host.equals(entity.getHost())
                && this.username != null && this.username.equals(entity.getUsername())
                && this.owner != null && this.owner.equals(entity.getOwner())
                && this.port == entity.getPort();
    }

    @Override
    public String toString() {
        return this.username + "@" + this.host + ":" + this.port;
    }
}
